

var Banner = P.createUi({
    _data:{},
    _create:function(){
        var me = this;
        var $widget = $('.widget-banner'),
            $block = $widget.find('.block'),
            $contents = $block.find('.content'),
            $points = $widget.find('.points'),
            count = $contents.length,
            interval = 0,
            cur = 0,
            bgMap = [
//                __uri("./banner0/bg.png"),
//                __uri("./banner03/bg.png"),
                __uri("./banner04/bg.png"),
//                __uri("./banner02/bg.png"),
                __uri("./banner1/bg.png"),
                __uri("./banner3/bg.png")
            ];

        this.data({
            "$widget":$widget,
            "$block":$block,
            "$contents":$contents,
            "$points":$points,
            "count":count,
            "interval":interval,
            "cur":cur,
            "bgMap":bgMap
        });
        $points.html(function(){
            var tpl = '';
            for(var i=0;i<count;i++){
                tpl+='<i></i>'
            }
            return tpl;
        }).css({
                'width':(25*count),
                'margin-left':'-'+(25*count)/2+'px'
            });

        setTimeout(function(){
            me.slider(cur);
        },100);
        me.start();
//        me.activity();
    },

    _init:function(){
        var me = this,
            $block = this.data('$block'),
            $widget = this.data('$widget'),
            $points = this.data('$points');

        $block.find('.content').show().click(function(){
            location.href=$(this).attr('data-url');
        });

        $widget.on("mouseover",function(){
            me.stop();
        }).on("mouseout",function(){
                me.start();
            });

        $points.find('i').on("mouseover",function(){
            me.stop();
            me.slider($(this).index());
        }).on("mouseout",function(){
                me.start();
            });

    },

    slider:function(index){
        var $block = this.data('$block'),
            $widget = this.data('$widget'),
            $points = this.data('$points'),
            bgMap = this.data('bgMap'),
            $contents = this.data('$contents');

        $block.css('background-image','url('+bgMap[index]+')');
        $contents.removeClass('active');
        if($.browser.msie&&parseInt($.browser.version)<9){
            $contents.hide();
            $contents.eq(index).show();
        }
        $contents.eq(index).addClass('active');
        $points.find('i').removeClass('active');
        $points.find('i').eq(index).addClass('active');
    },


    stop:function(){
        var interval = this.data('interval');
        interval && clearInterval(interval);
        this.data('interval',0)
    },

    start:function(){
        var me = this,
            count = this.data('count'),
            interval = this.data('interval');

        interval && clearInterval(interval);
        interval = setInterval(function(){
            var cur = me.data('cur');
            if(cur>=count-1){
                cur = 0;
                me.data('cur',0)
            }else{
                cur++;
            }
            me.data('cur',cur);
            me.slider(cur);
        },4000);
        this.data('interval',interval);
    },

    activity:function(){
        var $block = this.data('$block'),
            $hours = $block.find('.content0 .hours'),
            $minute = $block.find('.content0 .minute'),
            $second = $block.find('.content0 .second');

        setInterval(function(){
            var dateObj=new Date(),
                day = dateObj.getDay(),
                hours = dateObj.getHours(),
                minutes = dateObj.getMinutes(),
                seconds = dateObj.getSeconds();

            if(day == 5 && hours<13){
                if(hours<12){
                   return;
                }
                hours = 12-hours;
                if(hours==0 && seconds==0){
                    location.reload();
                }
            }else{
                hours = 23-hours;
            }

            minutes = 59-minutes;
            seconds  =  59-seconds;
            if(hours==0 && minutes==0 && seconds==0){
                location.reload();
            }
            hours = hours/10>=1?hours:'0'+hours;
            minutes = minutes/10>=1?minutes:'0'+minutes;
            seconds = seconds/10>=1?seconds:'0'+seconds;
            $hours.text(hours);
            $minute.text(minutes);
            $second.text(seconds);
        },1000);

    }

});

$.extend(exports,{
    Banner:Banner,
    banner:function(option){
        return new Banner(option);
    }
});